package com.bw.controller.comment;

import com.alibaba.dubbo.config.annotation.Reference;
import com.bw.entity.PageResult;
import com.bw.entity.Result;
import com.bw.pojo.comment.ProductReply;
import com.bw.pojo.goods.Brand;
import com.bw.pojo.goods.Sku;
import com.bw.service.comment.ProductReplyService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/productReply")
public class ProductReplyController {
    @Reference
    private ProductReplyService productReplyService;

    /**
     * 模糊查询+分页
     * @param
     * @return
     */
    @PostMapping("/findPage")
    public PageResult<ProductReply> findPage(@RequestBody Map<String,Object> searchMap,int page,int size){
        return productReplyService.findPage(searchMap, page, size);
    }


    @PostMapping("/findPageSearch")
    public PageResult<ProductReply> findPageSearch(@RequestBody Map<String, Object> searchMap, int page, int size) {
        return productReplyService.findPageSearch(searchMap,page,size);
    }

    /**
     * 分页
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/findPage")
    public PageResult<ProductReply> findPage(int page, int size){
        return  productReplyService.findPage(page,size);
    }
    /**
     * 管理员分页
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/findListPage")
    public PageResult<ProductReply> findListPage(int page, int size){
        return  productReplyService.findListPage(page,size);
    }
    /**
     * 分页
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/findBinPage")
    public PageResult<ProductReply> findBinPage(int page, int size){
        return  productReplyService.findBinPage(page,size);
    }

    @GetMapping("/delete")
    public Result delete(String id){
        productReplyService.delete(id);
        return new Result();
    }


    /**
     *
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public ProductReply findById(String id){
        ProductReply byId = productReplyService.findById(id);
        return byId;
    }



    /**
     * 根据商品id数组获得商品列表
     * @param searchMap
     * @return
     */
    @PostMapping("/findSkuListBySkuIds")
    public List<Sku> findSkuListBySkuIds(@RequestBody Map<String,Object> searchMap){
        return productReplyService.findSkuListBySkuIds(searchMap);
    }
    /**
     * 还原评论
     */
    @GetMapping("/restore")
    public Result restore(String id){
        productReplyService.restore(id);
        return new Result();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping ("/deleMany")
    public Result deleMany(@RequestBody String [] ids){
        System.out.println(ids);
        productReplyService.deleMany(ids);
        return new Result();
    }

    /**
     * 批量还原
     * @param ids
     * @return
     */
    @PostMapping("/resMany")
    public Result resMany(@RequestBody String [] ids){
        productReplyService.resMany(ids);
        return new Result();
    }

    /**
     * 删除追评
     */
    @GetMapping("/deleteFollow")
    public Result deleteFollow(String id){
        productReplyService.deleteFollow(id);
        return new Result();
    }
    //添加虚拟评论
    @PostMapping("/addVirtual")
    public Result addVirtual(@RequestBody Map<String,List<ProductReply>> searchMap){
        System.out.println(searchMap);
        System.out.println(searchMap.get("productReplies"));
        productReplyService.addVirtual(searchMap.get("productReplies"));
        return new Result();
    }

//    @PostMapping("/findByProductReplyId")
//    public List<StoreReply> findByProductReplyId(@RequestBody Map<String,Object> searchMap){
//        return storeReplyService.findByProductReplyId(searchMap);
//    }

}
